package com.example.shopping.api;

import com.example.shopping.shdatas.SHError;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Hashtable;

/**
 * Created by doanht on 12/5/13.
 */
public class SHDefaultParserDataManager implements SHParserDataManager {
    public SHParserData checkErrorParser;
    private Hashtable<String, SHParserData> hashTable;

    public SHDefaultParserDataManager() {
        super();
        this.hashTable = new Hashtable<String, SHParserData>();
    }

    public SHDefaultParserDataManager(SHParserData checkErrorParser) {
        super();
        this.checkErrorParser = checkErrorParser;
        this.hashTable = new Hashtable<String, SHParserData>();
    }

    public SHResponseData parseData(JSONObject response, String requestResponseType) throws org.json.JSONException {



        SHParserData parserData = getParseData(requestResponseType);
        if (parserData != null) {
            return parserData.parseData(response);
        }
        return null;
    }

    public SHParserData getParseData(String requestResponseType) {
        return hashTable.get(requestResponseType);
    }

    public void addParseData(SHParserData parserData) {
        if (parserData != null) {
            hashTable.put(parserData.requiredResponseType(), parserData);
        }
    }

    public void removeParseData(SHParserData parserData) {
        if (parserData != null) {
            hashTable.remove(parserData.requiredResponseType());
        }
    }

    public void removeAllParseData() {
        hashTable.clear();
    }
}
